<?php
declare (strict_types = 1);

namespace app\admin\controller;

use addons\Builder\facade\Builder;
use app\common\tool\Result;
use think\facade\View;
use think\Response;
use addons\Gallery\driver\Gallery;
//该文件为自动生成，请按需修改
class Learn extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Learn';

    protected $append = ['cateText'];
    public function index(): string
    {
       return Builder::Table()
           ->autoStructure($this->model, $this->pk, 'barDemo,200')
           ->addRightButtons(['edit' => ['size' => '60%'], 'delete'])
           ->addTopButtons(['add' => ['size' => '60%'], 'deleteAll'])
           ->addSearch([
               ['title', '标题', 'input,Like'],
           ])
           ->fetch();
    }
    public function add($tpl = 'learn/edit')
    {
        $qn_token= Gallery::getQnList();
        view::assign(
            [
                'info'=>[],
                'cate' => $this->model::getVideoList('',2),
                'qn_token'=>$qn_token['token'],
                'qn_url'=>$qn_token['url'],
                'domain_url'=>$qn_token['domain'],
            ]
        );
        return parent::add($tpl); // TODO: Change the autogenerated stub
    }

    public function edit($id = '', $tpl = 'learn/edit', $info = '')
    {
        $qn_token= Gallery::getQnList();
        view::assign(
            [
                'cate' => $this->model::getVideoList('',2),
                'qn_token'=>$qn_token['token'],
                'qn_url'=>$qn_token['url'],
                'domain_url'=>$qn_token['domain'],
            ]
        );
        return parent::edit($id, $tpl, $info); // TODO: Change the autogenerated stub
    }
}
